function toasterror(note) {
    return  $.toast({
        text: note,
        position: 'top-right',
        loaderBg:'#ff6849',
        icon: 'error',
        hideAfter: 3500
    });
}

function toastsuccess(note) {
    return  $.toast({
        text: note,
        position: 'top-right',
        loaderBg:'#ff6849',
        icon: 'success',
        hideAfter: 3500
    });
}



$('.pwd-form').submit(function (e) {
    e.preventDefault();
    swal({
            title: "",
            text: "确定修改么？",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "是的",
            closeOnConfirm: false
        },
        function () {
            $.ajax({
                type: "post",
                url: '/pwdEidt',
                data: $('.pwd-form').serialize(),// 你的formid
                async: false,
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                error: function (e) {
                    if (e.readyState === 4 && e.status === 422) {
                        for (var i in e.responseJSON) {
                            if (e.responseJSON[i] !== 'The given data was invalid.') {
                                err = e.responseJSON[i];
                                for (var j in err) {
                                    swal(err[j][0]);
                                }
                            }
                        }
                    }
                },
                success: function (data) {
                    console.log(data.message);
                    if (data.status === 1) {
                        swal(data.message, '', 'success');
                        $('.confirm').click(function () {
                            location.reload();
                        });
                    } else {
                        swal(data.message);
                    }
                }
            });
        })
});


function picajax(file) {
    var url;
    var formData = new FormData();
    formData.append('file', file);
    $.ajax({
        data: formData,
        type: "POST",
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        url: "/upload", /*填写后台上传文件的路径*/
        cache: false,
        contentType: false,
        async: false,
        processData: false,
        error:function () {

        },
        success: function (path) {/*url为上传成功后返回的图片路径*/
            url = path;
        }

    });
    return url;
}



$(document).ready(function () {
    var hidden = $('#hidden').val();
    if (hidden === 'hidden') {
        if ($('#status').val() === 1) {
            toastsuccess($('#message').val());
        } else {
            toasterror($('#message').val());
        }
    }
});